package com.www.applyword.ui.my;

import android.content.Intent;

import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.www.applyword.Constants.Constants;
import com.www.applyword.R;
import com.www.applyword.adapter.JobPositionAdapter;
import com.www.applyword.adapter.JobPositionAdapter2;
import com.www.applyword.base.BaseActivity;
import com.www.applyword.bean.ResultBean;
import com.www.applyword.http.CallBack;
import com.www.applyword.http.HttpClient;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;

/**
 * author : huang
 * date   : 2019/10/30 0030 10:11
 * version: 1.0
 */
public class JobPostionActivity extends BaseActivity {
    @BindView(R.id.rv_left)
    RecyclerView rv_left;
    @BindView(R.id.rv_right)
    RecyclerView rvRight;

    private JobPositionAdapter mHotJobAdapter;
    private JobPositionAdapter2 mHotJobAdapter2;

    private List<ResultBean> jobList = new ArrayList<>();
    private List<ResultBean> jobList2 = new ArrayList<>();

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.job_position);
        setTitle("请选择感兴趣的职位");
    }

    @Override
    protected void loadData() {
        rv_left.setLayoutManager(new LinearLayoutManager(JobPostionActivity.this));
        rv_left.setItemAnimator(new DefaultItemAnimator());
        mHotJobAdapter = new JobPositionAdapter(JobPostionActivity.this);
        rv_left.setAdapter(mHotJobAdapter);

        rvRight.setLayoutManager(new LinearLayoutManager(JobPostionActivity.this));
        rvRight.setItemAnimator(new DefaultItemAnimator());
        mHotJobAdapter2 = new JobPositionAdapter2(JobPostionActivity.this);
        rvRight.setAdapter(mHotJobAdapter2);
        getJobPosition();
    }

    private void getJobPosition() {
        Map<String, Object> params = new HashMap<>();
        params.put("ParentID","0");
        HttpClient.get(JobPostionActivity.this, Constants.GETPOSITIONLIST, params,new CallBack<List<ResultBean>>() {
            @Override
            public void onSuccess(List<ResultBean> result) {
                jobList.clear();
                jobList.addAll(result);
                mHotJobAdapter.replaceAll(jobList,true);

                mHotJobAdapter.setOnItemClickListener((viewHolder, view, i) -> {
                    Map<String, Object> params1 = new HashMap<>();
                    params1.put("ParentID",jobList.get(i).getPosition_ID());
                    HttpClient.get(JobPostionActivity.this, Constants.GETPOSITIONLIST, params1,new CallBack<List<ResultBean>>() {
                        @Override
                        public void onSuccess(List<ResultBean> result1) {
                            jobList2.clear();
                            jobList2.addAll(result1);
                            mHotJobAdapter2.replaceAll(jobList2,true);

                            mHotJobAdapter2.setOnItemClickListener((viewHolder1, view1, i1) -> {
                              String position_id =   jobList2.get(i1).getPosition_ID();
                              String position_name =   jobList2.get(i1).getPosition_Name();
                                Intent intent = new Intent();
                                intent.putExtra("position_id", position_id);
                                intent.putExtra("position_name", position_name);
                                setResult(20, intent);
                                finish();
                            });
                        }
                    });
                });
            }
        });
    }
}
